package edu.gatech.cc.liam.geometry.linear;

import java.util.ArrayList;

public class FeasibleSet {
	private static final long serialVersionUID = 1L;

	public ArrayList<Halfspace> equalities;
	public ArrayList<Halfspace> inequalities;
	
	public NPoint ub;
	public NPoint lb;
	
	public FeasibleSet() {
		equalities = new ArrayList<Halfspace>();
		inequalities = new ArrayList<Halfspace>();
	}
	
	public int getDimensions() {
		if(equalities.isEmpty() && inequalities.isEmpty())
			return 0;
		else if(!equalities.isEmpty())
			return equalities.get(0).normal.length;
		else
			return inequalities.get(0).normal.length;
	}
	
	public Polytope transformToPolytope() {
		Polytope p = new Polytope();
		for(Halfspace h : equalities) {
			p.addEqualityConstraint(h);
		}
		p.addAll(inequalities);
		for(int i=0; i<ub.dimensions(); i++) {
			NPoint n = new NPoint(ub.dimensions());
			n.values[i] = 1.0;
			Halfspace h = new Halfspace(n, -ub.values[i]);
			p.add(h);
		}
		for(int i=0; i<lb.dimensions(); i++) {
			NPoint n = new NPoint(lb.dimensions());
			n.values[i] = -1.0;
			Halfspace h = new Halfspace(n, lb.values[i]);
			p.add(h);
		}
		return p;
	}
}
